package com.smartens.boit.fragment.viewmode;

import android.annotation.SuppressLint;
import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.smartens.boit.bean.ListBeans;
import com.smartens.boit.bean.RecordDetail;
import com.smartens.boit.bean.RecordeDetail_datd;
import com.smartens.boit.util.HttpHelper;
import com.smartens.boit.util.Pickers;

import java.util.ArrayList;
import java.util.List;

public class AutoControlFragmentViewModel extends AndroidViewModel {
    private static final String TAG = "AutoControlFragmentView";
    private final HttpHelper helper;
    private final MutableLiveData<RecordDetail> deviceDetailData = new MutableLiveData<>();
    private final MutableLiveData<List<Pickers>> brightnessAdjustPlan = new MutableLiveData<>() ;
    private final MutableLiveData<List<RecordeDetail_datd>>groupList = new MutableLiveData<>();



    public AutoControlFragmentViewModel(@NonNull Application application) {
        super(application);
        helper = HttpHelper.getInstance();
    }


    public MutableLiveData<RecordDetail> getDeviceOnOffTimeDetail(boolean isPost) {
        if (isPost) {
            helper.getDeviceOnOffDetailResult(new HttpHelper.HttpCallBack<RecordDetail>() {
                @Override
                public void onSuccess(List<RecordDetail> result) {
                    RecordDetail recordDetail = result.get(0);
                    deviceDetailData.postValue(recordDetail);
                }

                @Override
                public void onFailure(String message) {
                    Log.d(TAG, "onFailure: " + message);
                    deviceDetailData.postValue(null);
                }
            });
        }
        return deviceDetailData;
    }


    public MutableLiveData<List<Pickers>> getBrightnessAdjustPlans(boolean isPost){
        if (isPost){
            helper.GetProjectList(new HttpHelper.HttpCallBack<ListBeans>() {
                @SuppressLint("LongLogTag")
                @Override
                public void onSuccess(List<ListBeans> result) {
                    Log.v("=====GetProjectDetail==获取方案成功", String.valueOf(result.size()));
                    List<Pickers> pickersList = new ArrayList<>();
                    for (ListBeans listBeans : result) {
                        Pickers pickers = new Pickers(listBeans.getProjectname(),listBeans.getProjectId());
                        pickersList.add(pickers);
                    }
                    brightnessAdjustPlan.postValue(pickersList);
                }

                @SuppressLint("LongLogTag")
                @Override
                public void onFailure(final String message) {
                    // Toast.makeText(getActivity(), "获取方案失败" , Toast.LENGTH_LONG).show();
                }
            });
        }
        return brightnessAdjustPlan;
    }


    public MutableLiveData<List<RecordeDetail_datd>> getGroupListData(boolean isPost){
        if (isPost){
            helper.GetDeviceGroupList("32FFD7055643373914721851", new HttpHelper.HttpCallBack<RecordeDetail_datd>() {
                @Override
                public void onSuccess(List<RecordeDetail_datd> result) {
                    groupList.postValue(result);
                }

                @Override
                public void onFailure(String message) {
                    groupList.postValue(null);
                }
            });
        }
        return groupList;
    }
}
